package com._58city.spark.app.ext.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com._58city.spark.app.ext.dto.DispCate;



/**
 * @author lihao
 * Cate的字典边，有业务线和各个级别cate的关系
 */
public class DispCateDao extends BaseDao implements ParameterizedRowMapper<DispCate>{
	
	public List<DispCate> select_all(){
		String sql = String.format("select * from %s", super.tableName);
		List<DispCate> result = this.jdbcTemplate.query(sql, this);
		if (null != result) {
			return result;
		} else {
			return new ArrayList<DispCate>();
		}
	}
	
	public DispCate select_by_cateid(long cateid) {
		try {
			String sql = String.format( "select * from %s where cate_id =?", super.tableName);
			DispCate result = this.jdbcTemplate.queryForObject(sql, this, super.params(cateid));
			return result;
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	public DispCate mapRow(ResultSet rs, int rowNum) throws SQLException {
		DispCate res = new DispCate();
		res.setBusiness_type(rs.getString("business_type"));
		res.setBusiness_type_name(rs.getString("business_type_name"));
		res.setCate_id(rs.getLong("cate_id"));
		res.setCate_name(rs.getString("cate_name"));
		res.setCate1_id(rs.getLong("cate1_id"));
		res.setCate1_name(rs.getString("cate1_name"));
		res.setCate2_id(rs.getLong("cate2_id"));
		res.setCate2_name(rs.getString("cate2_name"));
		res.setCate3_id(rs.getLong("cate3_id"));
		res.setCate3_name(rs.getString("cate3_name"));
		res.setCate4_id(rs.getLong("cate4_id"));
		res.setCate4_name(rs.getString("cate4_name"));
		res.setCate5_id(rs.getLong("cate5_id"));
		res.setCate5_name(rs.getString("cate5_name"));
		res.setBusiness_type_biz(rs.getString("business_type_biz"));
		res.setBusiness_type_name_biz(rs.getString("business_type_name_biz"));
		return res;
	}

}
